package com.tool_stdy.concurrent;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by yan_li on 2016/1/10.
 */
public class ThreadInterrupt {
    public static void main(String[] args) throws InterruptedException {
        Thread1 t1 = new Thread1();
        t1.start();
        Thread.sleep(500);
        t1.interrupt();
        System.out.println("Over");
    }
}

class Thread1 extends Thread {

    Lock lock = new ReentrantLock();
    @Override
    public void run() {
        int i = 0;
        while (true) {
            System.out.println(Thread.currentThread().isInterrupted());
            try {
                lock.lockInterruptibly();
                System.out.println("线程--:" + Thread.currentThread().getName() + "run..." + i);
                i++;
                Thread.sleep(200);
            } catch (InterruptedException e) {
                System.out.println("线程被中断.." + Thread.currentThread().getName());
                break;
            }
        }
    }
}